package com.briup.store.config;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * 支付属性加载配置类（支付宝沙箱）
 * @author qinyc
 * @date 2024/06/23
 */
@Data
@Configuration
@ConfigurationProperties("alipay")
public class AliPayConfig {
    // 应用Id
    private String appId;
    // 应用私有
    private String appPrivateKey;
    // 支付宝公钥
    private String alipayPublicKey;
    //回调地址
    private String notifyUrl;
    //协议
    private String protocol;
    //网关主机
    private String gatewayHost;
    //签名类型(加密算法)
    private String signType;

    //设置字符集的编码格式 utf-8
    private String charset;
    //网关服务器地址
    private String gatewayUrl;
    //发送数据的格式,  目前为json
    private String format;


    @PostConstruct
    public void init() {
        System.out.println("=======支付宝SDK准备初始化=======");
        // 设置参数（全局只需设置一次）
        Config config = new Config();
        config.protocol = this.protocol;
        config.gatewayHost = this.gatewayHost;
        config.signType = this.signType;
        config.appId = this.appId;
        config.merchantPrivateKey = this.appPrivateKey;
        config.alipayPublicKey = this.alipayPublicKey;
        config.notifyUrl = this.notifyUrl;
        Factory.setOptions(config);
        System.out.println("=======支付宝SDK初始化成功=======");
    }
}